{# empty Twig template #}
<div class="left" id="formcontent"> 
<div class="title"><h5>Create Source </h5></div>
           
        <!-- Form -->
<form action="{{ path('em_src_create') }}" method="post" id="valid" class="mainForm" {{ form_enctype(form) }}>
<fieldset>
    <div class="widget">    
	 <div class="head" id="loading"><h5 class="iHome">Create Source</h5></div>
	 {% if status_form==2 %}
	<div class="nNote nFailure hideit">
		<p><strong>FAILURE: </strong>Oops sorry. Something was wrong, try again.</p>
	</div>
	 {% endif %}
	 
    {% block form_row %}
	
	<div class="rowElem">
		
        {{ form_widget(form) }}
	</div>
	<div class="fix"></div>
	{% endblock form_row %}
	
    <button type="submit"  class="greyishBtn submitForm" >New Source</button>
    <div class="fix"></div>
	</div>
	</fieldset>
</form>
 </div>       
        <!--Derecho-->
<div class="right" id="listContent"> 
       <!-- Dynamic table -->
		<div class="title" id="list"><h5>Source list </h5> </div>
		
	   
				<div class="table">

					<div class="head"><h5 class="iFrames">Source </h5></div>
					 <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
						<thead>
							<tr>
								<th>Id</th>
								<th>Name</th>
								<th>Description</th>
								<th>Actions</th>
								
							</tr>
						</thead>
						<tbody>
						   {% for src in source %}
						   
							   <tr class="gradeA">
							   <td class="center">{{src.id}}</td>
							   <td class="center">{{src.name}}</td>
							   <td class="center">{{src.description}}</td>
								<td class="center">
									<a href="#" id="edit" onclick="find('{{ path('em_src_find', {'id':src.id}) }}');"><img src="{{asset('bundles/news/images/icons/color/pencil.png')}}" alt=""></a> &nbsp;
                                                                        <a href="#" id="{{src.id}}" onclick="delete_source(this);"><img src="{{asset('bundles/news/images/icons/color/cross.png')}}" alt=""></a> &nbsp;
									
								</td>
								
							</tr>
						
							{% endfor %}
						</tbody>
					</table>
					  
				</div>

			<div class="fix"></div>	
                          {%if status!=0%}
                            {% if ex is defined  %}
                            {%if status==3%}
                            <div class="nNote nFailure hideit">
                                 <p><strong>FAILURE: </strong> 
                            {%endif%}
                            {%if status==1%}
                            <div class="nNote nSuccess hideit">
                                 <p><strong>SUCCESS: </strong> 
                            {%endif%}
                            {%if status==2%}
                                 
                            <div class="nNote nInformation hideit">
                                <p><strong>INFO: </strong> 
                            {%endif%}
                                 {{ ex }} </p>
                            </div>

                            {% endif %}
                        {% endif %}
		</div>
      
<script>
function exr() {
 console.log("update");  
 var action=$('#valid').attr('action');
 var datos = $('#valid').serialize();     
 
 $.ajax({type: 'POST', url:action, script:true, cache:false,data: datos,
                   // beforeSend: function(response){ $('#formcontent').html('<div align="center"><img src="{{asset('bundles/news/images/loaders/loader8.gif')}}" alt="" class="p12"><br>Loading data...</div>');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){

			}else{
                       // console.log(response);
                        $('#all').html(response);
                        
			}
                } });
        return false;
 
 
}
 $( "#valid" ).submit(function( event ) {
 console.log("create");  
 var action=$('#valid').attr('action');
 var datos = $(this).serialize();     
 
 $.ajax({type: 'POST', url:action, script:true, cache:true,data: datos,
                   // beforeSend: function(response){ $('#formcontent').html('<div align="center"><img src="{{asset('bundles/news/images/loaders/loader8.gif')}}" alt="" class="p12"><br>Loading data...</div>');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){

			}else{
                       // console.log(response);
                        $('#all').html(response);
                        
			}
                } });
        return false;
 
 
});
function find(url){
    console.log("find");
    $.ajax({type: 'get', url:url, script:true, cache:true,
                        beforeSend: function(response){ $('#loading').append('<div class="loader"><img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt=""></div>');},
                        error: function(){ $('#formcontent').html('<div class="nNote nFailure hideit"><p><strong>FAILURE: </strong>Oops sorry. That action is not valid, or our servers have gone bonkers</p></div>');},
                        success: function(response) {
                                 if (response === "false"){

                                 }else
                                 {
                                
                                    $('#formcontent').html(response);

                                 }
                         } });

}
function delete_source(obj){
    var url='{{ path('em_src_delete', {'id':'source_id'}) }}';
    url = url.replace("source_id", obj.id);
  // console.log(obj.id);
   console.log(url);
    $.ajax({type: 'POST', url:url, script:true, cache:true,
                        beforeSend: function(response){ $('#list').append('<div class="loader"><img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt=""></div>');},
                        //error: function(){ $('#listContent').html('<div class="nNote nFailure hideit"><p><strong>FAILURE: </strong>Oops sorry. That action is not valid, or our servers have gone bonkers</p></div>');},
                        error: function(response){$('#listContent').html(response.responseText );},
                        success: function(response) {
                                 if (response === "false"){

                                 }else
                                 {
                                
                                    $('#listContent').html(response);
                                    console.log(response);

                                 }
                         }});

}

</script>